$(document).ready(function(){
    
   function loadComments(id){
      
      $.post('comment/comment.actions.php', {
           "action":"loadCommentsForChallenge",
           "challenge_id":id
       }, function(data){
           
           //console.log(data);
           var commentView=$('#displayComment');
           commentView.html("");
           $.each(data, function(index, value) {
              
              
              commentView.append("<tr><th>"+value.username+"  -  "+value.date_time+"</th></tr><tr><td>"+value.comment+"</td></tr>");
              
             // value.comment;
              
           });
           
           
       },"json");
       
   }
    
   loadComments(challenge_id_var);
   
   
   $('#submitComment').click(function(){
       
       //console.log($('#newCommentForm').serialize());
       
       $.post('comment/comment.actions.php', $('#newCommentForm').serialize()+"&action=newComment", function(data){
           console.log(data);
           loadComments(challenge_id_var);
       });

return false;

   });
   
   //$('#hover').hover(function(){$('#popup').show();}, function(){$('#popup').hide();});
   
   
   
   
});


$(document).ready(function(){
   
   
    $(".hover").mousemove(function(e){
        $(this).next('.popup').show().css({
            top: (e.pageY + -240) + "px",
            left: (e.pageX + -400) + "px"
        });
    });
    $(".hover").mouseout(function(e){
         $(".hover").next('.popup').hide();
    });
});
